class_name CPlayerDataDefine

var m_UUID
var tblSevenDayLogin: CSevenDayLogin
var tblSevenDayTask: CSevenDayTask
var tblCharConst: CCharConst
var tblCharBase: CCharBase
var tblMaterialBag: CMaterialBag
var tblBagItem: CBagItemArray
var tblClassBagItem: CClassBagItemArray
var tblClassDressedItem: CClassDressedItemArray
var tblInventory: CInventoryArray
var tblPlayerMoney: CPlayerMoneyArray
var tblPlayerSkill: CPlayerSkillArray
var tblCharFunctionTime: CCharFunctionTimeArray
var tblPlayerScene: CPlayerSceneArray
var tblRuntimeData: CRuntimeData
var tblTaskInfo: CTaskInfoArray
var tblPet: CPetArray


static func GetType():
    return TableCommonDefine.EDataDefineType.eDDT_Player


func _init(_uuid, _context):
    m_UUID = _uuid
    self.Reset()


func ClearData():
    # "client none"
    pass


func Reset():
    self.tblSevenDayLogin = CSevenDayLogin.new(self.m_UUID)
    self.tblSevenDayTask = CSevenDayTask.new(self.m_UUID)
    self.tblCharConst = CCharConst.new(self.m_UUID)
    self.tblCharBase = CCharBase.new(self.m_UUID)
    self.tblMaterialBag = CMaterialBag.new(self.m_UUID)
    self.tblBagItem = CBagItemArray.new(self.m_UUID)
    self.tblClassBagItem = CClassBagItemArray.new(self.m_UUID)
    self.tblClassDressedItem = CClassDressedItemArray.new(self.m_UUID)
    self.tblInventory = CInventoryArray.new(self.m_UUID)
    self.tblPlayerMoney = CPlayerMoneyArray.new(self.m_UUID)
    self.tblPlayerSkill = CPlayerSkillArray.new(self.m_UUID)
    self.tblCharFunctionTime = CCharFunctionTimeArray.new(self.m_UUID)
    self.tblPlayerScene = CPlayerSceneArray.new(self.m_UUID)
    self.tblRuntimeData = CRuntimeData.new(self.m_UUID)
    self.tblTaskInfo = CTaskInfoArray.new(self.m_UUID)
    self.tblPet = CPetArray.new(self.m_UUID)


func GetUUID():
    return self.m_UUID



func GetDBDefine():
    return null


func GetDataDefineName():
    return "CPlayerDataDefine"



func UnPack(_bufferStream, _size, _pos):
    assert( _bufferStream.GetDataSize() == _size )
    _bufferStream.SetPosition( _pos )
    var nCount = 0
    var nUUID = 0

    self.tblSevenDayLogin.UnPack(_bufferStream)
    self.tblSevenDayTask.UnPack(_bufferStream)
    self.tblCharConst.UnPack(_bufferStream)
    self.tblCharBase.UnPack(_bufferStream)
    self.tblMaterialBag.UnPack(_bufferStream)
    self.tblBagItem.UnPack(_bufferStream)
    self.tblClassBagItem.UnPack(_bufferStream)
    self.tblClassDressedItem.UnPack(_bufferStream)
    self.tblInventory.UnPack(_bufferStream)
    self.tblPlayerMoney.UnPack(_bufferStream)
    self.tblPlayerSkill.UnPack(_bufferStream)
    self.tblCharFunctionTime.UnPack(_bufferStream)
    self.tblPlayerScene.UnPack(_bufferStream)
    self.tblRuntimeData.UnPack(_bufferStream)
    self.tblTaskInfo.UnPack(_bufferStream)
    self.tblPet.UnPack(_bufferStream)


func GetTableByTableId(_nTblId):
    # var szObjName = 'tbl' .. AllTables[_nTblId]
    # if self[szObjName] == null :
    #     return null
    
    # return self[szObjName]
    return null


func SynFieldData(_nOperType,_tableID, _nDataUUID, _fieldID,  _dataStream, _nBufferSize, _nPos):

    var tbl = self.GetTableByTableId(_tableID)
    if null == tbl :
        return false
    
    if _nOperType == TableCommonDefine.eCTOp_Update:
        var buffStream = CBufferStream.new(null);
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        return tbl.UnPackField( _fieldID,buffStream, _nBufferSize)
    elif _nOperType == TableCommonDefine.eCTOp_Insert:
        var buffStream = CBufferStream.new(null)
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        tbl.AddField(_fieldID,buffStream)
        return true
    elif _nOperType == TableCommonDefine.eCTOp_Delete:
        tbl.DelField(_fieldID)
        return true
    elif _nOperType == TableCommonDefine.eCTOp_Assign:
        var buffStream = CBufferStream.new(null)
        buffStream.Load(_dataStream, _nPos, _nBufferSize)
        var nArraySize = buffStream.ReadUint32()
        tbl.SetCurNum(nArraySize)
    
    return false


func AddTableListener(_szTable, _szField, _szCallback, caller):
    var szFunGetTableName = "Get%s" % [ _szTable]
    if not has_method(szFunGetTableName):
        return false
    
    var table = call(szFunGetTableName)
    table.AddEventListener(_szField, _szCallback, caller)


func RemoveTableListener(_szTable, _szField, _szCallback, caller):
    var szFunGetTableName = "Get%s" % [ _szTable]
    if not has_method(szFunGetTableName):
        return false
    
    var table = call(szFunGetTableName)
    table.RemoveEventListener(_szField, _szCallback, caller)

func CopyFrom(_pOther):
    self.m_UUID = _pOther.m_UUID
    self.tblSevenDayLogin.CopyFrom(_pOther.tblSevenDayLogin)
    self.tblSevenDayTask.CopyFrom(_pOther.tblSevenDayTask)
    self.tblCharConst.CopyFrom(_pOther.tblCharConst)
    self.tblCharBase.CopyFrom(_pOther.tblCharBase)
    self.tblMaterialBag.CopyFrom(_pOther.tblMaterialBag)
    self.tblBagItem.CopyFrom(_pOther.tblBagItem)
    self.tblClassBagItem.CopyFrom(_pOther.tblClassBagItem)
    self.tblClassDressedItem.CopyFrom(_pOther.tblClassDressedItem)
    self.tblInventory.CopyFrom(_pOther.tblInventory)
    self.tblPlayerMoney.CopyFrom(_pOther.tblPlayerMoney)
    self.tblPlayerSkill.CopyFrom(_pOther.tblPlayerSkill)
    self.tblCharFunctionTime.CopyFrom(_pOther.tblCharFunctionTime)
    self.tblPlayerScene.CopyFrom(_pOther.tblPlayerScene)
    self.tblRuntimeData.CopyFrom(_pOther.tblRuntimeData)
    self.tblTaskInfo.CopyFrom(_pOther.tblTaskInfo)
    self.tblPet.CopyFrom(_pOther.tblPet)



func GetSevenDayLogin():    
    return self.tblSevenDayLogin

func GetSevenDayTask():    
    return self.tblSevenDayTask

func GetCharConst():    
    return self.tblCharConst

func GetCharBase():    
    return self.tblCharBase

func GetMaterialBag():    
    return self.tblMaterialBag

func GetBagItem():    
    return self.tblBagItem

func GetClassBagItem():    
    return self.tblClassBagItem

func GetClassDressedItem():    
    return self.tblClassDressedItem

func GetInventory():    
    return self.tblInventory

func GetPlayerMoney():    
    return self.tblPlayerMoney

func GetPlayerSkill():    
    return self.tblPlayerSkill

func GetCharFunctionTime():    
    return self.tblCharFunctionTime

func GetPlayerScene():    
    return self.tblPlayerScene

func GetRuntimeData():    
    return self.tblRuntimeData

func GetTaskInfo():    
    return self.tblTaskInfo

func GetPet():    
    return self.tblPet


